package com.lpf.springbootdemo.controller;

import org.springframework.web.bind.annotation.*;

import javax.servlet.http.Cookie;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 1、@PathVariable注解：路径变量
 * 2、@RequestHeader注解：获取请求头的注解
 * 3、@RequestParam注解：获取请求参数
 * 4、@CookieValue注解：获取cookie值
 * 5、@RequestAttribute注解：获取request域属性
 * 6、@RequestBody注解：获取请求体
 * 7、@MatrixVariable注解：矩阵变量
 * @author LPF
 */
@RestController
public class ParameterTestController {

    @GetMapping("/car/{id}/owner/{username}")
    public Map<String, Object> getCar(@PathVariable("id") Integer id,
                                      @PathVariable("username") String name,
                                      @PathVariable Map<String, String> pv,
                                      @RequestHeader("User-Agent") String userAgent,
                                      @RequestHeader Map<String, String> headers,
                                      @RequestParam("age") Integer age,
                                      @RequestParam("inters") List<String> inters,
                                      @RequestParam Map<String, String> params,
                                      @CookieValue("Idea-2ee6cc3a") String _ga,
                                      @CookieValue("Idea-2ee6cc3a") Cookie cookie){
        Map<String, Object> map = new HashMap<>();

//        map.put("id", id);
//        map.put("name", name);
//        map.put("pv", pv);
//        map.put("User-Agent", userAgent);
//        map.put("headers", headers);
        map.put("age", age);
        map.put("inters", inters);
        map.put("params", params);
        map.put("_ga", _ga);
        System.out.println(cookie.getName() + cookie.getValue());
        return map;
    }


    /**
     * post请求
     * @param content
     * @return
     */
    @PostMapping("/save")
    public Map postMethod(@RequestBody String content){
        Map<String, Object> map = new HashMap<>();

        map.put("content", content);
        return map;
    }
}
